<?php include_once('model/karyawan.php')?>
<?php $karyID = $_COOKIE_DATA->username; ?>
<script>
APP.totalPointKaryawan = {
	action: 'proc/admin/totalPointKaryawan.php',
	periode1: null,
	periode2: null,
	load_graph: function (){
		var showImage = function(){
			var img = $('graphContainer').getElement('img');
			if (img == null) return;
			if (img.complete) $('graphContainer').tween('opacity',1);	
			else showImage.delay(1000);
		}
		
		var form = $('totalPointKaryawan-form');
		var kary_id = form.kary_id.value;
		var kary_dept = form.kary_dept.value;
		var periode1 = form.periode1;
		var periode2 = form.periode2;
		
		$('graphContainer').tween('opacity',0);	
		FBModal_loading("Loading...", "Generating graph", true, true);
		doRequest( APP.totalPointKaryawan.action , 'post', 'proc=graph&kary_id='+kary_id+'&kary_dept='+kary_dept+'&periode1='+periode1.value+'&periode2='+periode2.value, null,
			function(res){
				if (res) {			
					//alert(res);
					res = res.replace(/href/gi,'onclick');
					$('graphContainer').empty().set('html', res)
						.getElements('area').each(function(item){
							item.addEvent('click', function(e){ new Event(e).stop(); })
								.href="#";
						});
				}
				else{
					$('graphContainer').empty();
				}
				showImage.delay(1000);
				FBModal_hide();
			});
	},
		
	load_drillGraph: function (data){
		var proc = data.type==1? 
			"proc=graph-drill-karyawan&kary_id="+data.kary_id+"&kary_dept="+data.kary_dept+
			"&month="+data.month+"&year="+data.year : 
			"proc=graph-drill-departemen&kary_dept="+data.kary_dept+"&month="+data.month+"&year="+data.year;
		
		FBModal_show2( APP.totalPointKaryawan.action , 'post', proc, true, true, null);	
	}
}
window.addEvent('domready', function(){			
	var form = $('totalPointKaryawan-form');	
	//APP.totalPointKaryawan.load_graph();
	
	APP.totalPointKaryawan.periode1 = dtpicker_attach0(form.periode1, {timePicker:false, format: 'F-Y', 
		maxDate: { date: <?php echo time()?>, format: 'U' },
		onClose: function(){ 
			APP.totalPointKaryawan.periode2.options.minDate = {date:APP.totalPointKaryawan.periode1.attachTo.value, format:'U'};
			APP.totalPointKaryawan.periode2.formatMinMaxDates();
			APP.totalPointKaryawan.load_graph();
		}
	});
	APP.totalPointKaryawan.periode2 = dtpicker_attach0(form.periode2, {maxDate:{ date: <?php echo time()?>, format: 'U' }, 
		timePicker:false, format: 'F-Y', onClose: function(){ load_graph() } 
	});
});
</script>
<form id="totalPointKaryawan-form" name="totalPointKaryawan">
<table width="100%" border="0">
<tr>
    <td width="100" align="right">Karyawan : </td>
    <?php $kary = mysql_fetch_assoc( kary_load($karyID) );?>
    <td><input name="kary_nama" type="text" readonly="readonly" value="<?php echo $kary['NAMA_KARYAWAN']?>" />
    				<input name="kary_id" type="hidden" value="<?php echo $karyID?>" /></td>
</tr>
<tr>
    <td align="right">Departemen : </td>
    <td>
    <select name="kary_dept">
    <?php $rsjab = RELASIJABATAN_load($karyID)?>
	<?php while ($row = mysql_fetch_assoc($rsjab)):?>
    <option value="<?php echo $row['ID_DEPARTMENT']?>" divisi="<?php echo $row['NAMA_DIVISI']?>" departemen="<?php echo $row['NAMA_DEPARTMENT']?>"><?php echo $row['NAMA_DEPARTMENT']?></option>
    <?php endwhile;?>
    </select></td>
</tr>
<tr>
    <td align="right">Periode : </td>
    <td><input type="text" name="periode1" value="<?php echo time()?>" /> - <input name="periode2" type="text" value="<?php echo time()?>" /></td>
</tr>
</table>
</form>